4 // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
6 // The use and distribution terms for this software are contained in the file
7 // named license.txt, which can be found in the root of this distribution.
8 // By using this software in any fashion, you are agreeing to be bound by the
9 // terms of this license.
11 // You must not remove this notice, or any other, from this software.
16 namespace Microsoft
.JScript
{
19 using System
.Collections
;
20 using System
.Reflection
;
22 internal class ScriptObjectPropertyEnumerator
: IEnumerator
{
23 private ArrayList enumerators
;
24 private ArrayList objects
;
26 private SimpleHashtable visited_names
;
28 internal ScriptObjectPropertyEnumerator(ScriptObject obj
){
29 obj
.GetPropertyEnumerator(this.enumerators
= new ArrayList(), this.objects
= new ArrayList());
31 this.visited_names
= new SimpleHashtable(16);
34 public virtual bool MoveNext(){
35 if (this.index
>= this.enumerators
.Count
)
37 IEnumerator ienum
= (IEnumerator
)this.enumerators
[this.index
];
38 bool result
= ienum
.MoveNext();
40 this.index
++; return this.MoveNext();
42 Object ob
= ienum
.Current
;
44 FieldInfo field
= ob
as FieldInfo
;
46 JSPrototypeField pfield
= ob
as JSPrototypeField
;
47 if (pfield
!= null && pfield
.value is Missing
)
48 return this.MoveNext();
50 Object val
= field
.GetValue(this.objects
[this.index
]);
52 return this.MoveNext();
53 }else if (ob
is String
)
55 else if (ob
is MemberInfo
)
56 pname
= ((MemberInfo
)ob
).Name
;
58 pname
= ob
.ToString();
59 if (this.visited_names
[pname
] != null)
60 return this.MoveNext();
61 this.visited_names
[pname
] = pname
;
65 public virtual Object Current
{
67 Object ob
= ((IEnumerator
)this.enumerators
[this.index
]).Current
;
69 return ((MemberInfo
)ob
).Name
;
75 public virtual void Reset(){
77 foreach(System
.Collections
.IEnumerator e
in this.enumerators
)
79 this.visited_names
= new SimpleHashtable(16);